package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.vo.AppCategoryVo;
import com.ruoyi.system.domain.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.FoodCategoryMapper;
import com.ruoyi.system.domain.FoodCategory;
import com.ruoyi.system.service.IFoodCategoryService;

/**
 * 商家的食物分类Service业务层处理
 * 
 * @author Wxl
 * @date 2022-03-16
 */
@Service
public class FoodCategoryServiceImpl implements IFoodCategoryService 
{
    @Autowired
    private FoodCategoryMapper foodCategoryMapper;

    /**
     * 查询商家的食物分类
     * 
     * @param id 商家的食物分类主键
     * @return 商家的食物分类
     */
    @Override
    public FoodCategory selectFoodCategoryById(Long id)
    {
        return foodCategoryMapper.selectFoodCategoryById(id);
    }

    /**
     * 查询商家的食物分类列表
     * 
     * @param foodCategory 商家的食物分类
     * @return 商家的食物分类
     */
    @Override
    public List<FoodCategory> selectFoodCategoryList(FoodCategory foodCategory)
    {
        return foodCategoryMapper.selectFoodCategoryList(foodCategory);
    }

    /**
     * 新增商家的食物分类
     * 
     * @param foodCategory 商家的食物分类
     * @return 结果
     */
    @Override
    public int insertFoodCategory(FoodCategory foodCategory)
    {
        foodCategory.setCreateTime(DateUtils.getNowDate());
        return foodCategoryMapper.insertFoodCategory(foodCategory);
    }

    /**
     * 修改商家的食物分类
     * 
     * @param foodCategory 商家的食物分类
     * @return 结果
     */
    @Override
    public int updateFoodCategory(FoodCategory foodCategory)
    {
        return foodCategoryMapper.updateFoodCategory(foodCategory);
    }

    /**
     * 批量删除商家的食物分类
     * 
     * @param ids 需要删除的商家的食物分类主键
     * @return 结果
     */
    @Override
    public int deleteFoodCategoryByIds(Long[] ids)
    {
        return foodCategoryMapper.deleteFoodCategoryByIds(ids);
    }

    /**
     * 删除商家的食物分类信息
     * 
     * @param id 商家的食物分类主键
     * @return 结果
     */
    @Override
    public int deleteFoodCategoryById(Long id)
    {
        return foodCategoryMapper.deleteFoodCategoryById(id);
    }

    @Override
    public List<CategoryVo> getByShopId(Long shopId) {
        List<FoodCategory> shop_id = foodCategoryMapper.selectFoodCategoryListByShopId(shopId);
        List<CategoryVo> categoryList = new ArrayList<>();
        for (FoodCategory foodCategory : shop_id) {
            CategoryVo categoryVo = new CategoryVo();
            categoryVo.setLabel(foodCategory.getName());
            categoryVo.setValue(foodCategory.getId());
            categoryList.add(categoryVo);
            }
        return categoryList;
    }

    @Override
    public List<AppCategoryVo> getByShopIdForApp(Long shopId) {
        List<FoodCategory> shop_id = foodCategoryMapper.selectFoodCategoryListByShopId(shopId);
        List<AppCategoryVo> categoryList = new ArrayList<>();
        for (FoodCategory foodCategory : shop_id) {
            AppCategoryVo categoryVo = new AppCategoryVo();
            categoryVo.setName(foodCategory.getName());
            categoryVo.setNumber(0L);
            categoryVo.setId(foodCategory.getId());
            categoryList.add(categoryVo);
        }
        return categoryList;
    }
}
